<!-- 房产信息 -->
<template>
  <view>
    <zh-form :transprent="true" v-model="form" inputAlign="right" :label-width="200" :margin="[0, 24]" :padding="[10, 0]">
      <zh-card :width="620">
        <template v-slot:title>
          <view style="border-left: 10rpx solid #2f54eb">
            <zh-text :fontSize="36" class="text-weight-b pl-10" :label="'房产信息' + form.index"></zh-text>
          </view>
        </template>
        <template v-slot:status>
          <tm-icon :fontSize="42" :name="data.hiddenFlag ? 'tmicon-eye-slash' : 'tmicon-eye'" style="margin: 0 20rpx" @tap="changeSensitive"></tm-icon>
        </template>
        <template v-slot:content>
          <zh-form-desc field="address" placeholder="未获取到房产地址信息" v-model="form.address" label="房产地址" :transprent="true"></zh-form-desc>
          <zh-form-desc field="realProperty" placeholder="未获取到不动产权证号信息" v-model="form.realProperty" label="不动产权证号" :transprent="true"></zh-form-desc>
          <zh-form-desc field="registerDate" placeholder="未获取到登记时间" v-model="form.registerDate" label="登记时间" :transprent="true"></zh-form-desc>
          <zh-sheet v-if="!props.myCheckInfo.bmFlag && !form.enrollFlag&&(props.myCheckInfo.fcCheck.ssBaseFlag||props.myCheckInfo.fcCheck.showXqFlag)" :margin="[0, 20]" :round="3" :padding="[20, 20]" color="deep-orange" text>
            <zh-text v-if="form.useFlag === '1'&&props.myCheckInfo.fcCheck.showXqFlag">本房产三年内有入学记录，不能用于今年入学。如果房产使用信息有误，可<span style="color:#3B5CF0;font-weight: 600;" @click="gotoAppeal('1')">前往申诉</span>。</zh-text>
            <zh-text v-if="form.useFlag === '0'&&(props.myCheckInfo.fcCheck.ssBaseFlag||props.myCheckInfo.fcCheck.showXqFlag)">如果房产基本信息有误，可<span style="color:#3B5CF0;font-weight: 600;" @click="gotoAppeal( '2')">前往申诉</span>。</zh-text>
          </zh-sheet>
          <view v-if="props.myCheckInfo.fcCheck.showXqFlag&&form.useFlag !== '1'" style="padding-top: 40rpx">
            <view style="border-left: 10rpx solid #2f54eb">
              <zh-text :fontSize="36" class="text-weight-b pl-10" label="房产所在学区信息"></zh-text>
            </view>

            <view
              :class="!elderFlag ? 'flex-row-center-start' : ''"
              style="padding-top: 20rpx"
              :key="'schoolHousehold' + index"
              v-for="(schoolItem, index) in form.schoolDistrictVOList"
            >
              <view class="flex-row-center-start">
                <tm-icon name="tmicon-home" :fontSize="30" color="primary"></tm-icon>
                <zh-text class="pl-5" :fontSize="30" :label="schoolItem.schoolName"></zh-text>
              </view>
              <zh-tag :followTheme="false" v-if="schoolItem.nativeFlag === '1'" color="orange" size="n" label="原住民可就读"></zh-tag>
            </view>
            <zh-sheet v-if="props.myCheckInfo.hjCheck.ssXqFlag && !props.myCheckInfo.bmFlag && !form.bmFlag" :margin="[0, 20]" :shadow="3" :round="5" :padding="[20, 20]" color="deep-orange" text>
              <zh-text >如果房产信息对应学区有误，可<span style="color:#3B5CF0;font-weight: 600;" @click="gotoAppeal('3')">前往申诉</span>。如果学区未显示请联系学校。</zh-text>
            </zh-sheet>
            <zh-sheet v-if="!props.myCheckInfo.hjCheck.ssXqFlag && !props.myCheckInfo.bmFlag && !form.bmFlag" :margin="[0, 20]" :shadow="3" :round="5" :padding="[20, 20]" color="deep-orange" text>
              <zh-text >如果房产信息对应学区有误，请联系学校。</zh-text>
            </zh-sheet>
          </view>
        </template>
        <zh-message ref="messageRef" :duration="2000"></zh-message>
      </zh-card>
    </zh-form>
  </view>
</template>
<script lang="ts" setup>
import { ref, reactive, onMounted, computed, watch } from 'vue';
import { system } from '@/store';
// ------------------接收传入参数(组件)-------------------
const props = defineProps({
  myCheckInfo: {
    type: Object,
    default: () => {},
  },
  //房产信息
  houseInfo: {
    type: Object,
    default: () => {},
  },
  index: {
    type: Number,
    default: 0,
  },
});

// ------------------变量区------------------------------
let messageRef = ref();
const elderFlag = computed(() => {
  return system.uiStyle === 'elder';
});
let form = ref<any>(Object.assign({}, props.houseInfo));
let oldForm = ref<any>(Object.assign({}, props.houseInfo));
// 主数据
const data = reactive({
  //脱敏
  hiddenFlag: true,
});
// ------------------全局操作------------------------------

// ------------------方法区--------------------------------
const CallPhone = (e: any) => {
  //拨打热线
  let zlbFlag = false;
  // #ifdef H5
  zlbFlag = system.zlbFlag;

  //#endif
  if (zlbFlag) {
    if (ZWJSBridge) {
      ZWJSBridge.phoneCall({
        corpId: e,
      })
        .then((result: any) => {
          console.error(result);
        })
        .catch((error: any) => {
          console.error(error);
        });
    } else {
      uni.makePhoneCall({
        phoneNumber: e,
      });
    }
  } else {
    uni.makePhoneCall({
      phoneNumber: e,
    });
  }
};
const gotoAppeal = (type: String) => {
  //前往房产信息申诉
  $router.push('/pages/edu/appeal/appeal', { type: type, id: form.value.houseId });
};
//前往我的申诉
const gotoMyAppeal = () => {
  $router.replace('/pages/edu/appeal/myAppeal', {});
};
const changeSensitive = () => {
  data.hiddenFlag = !data.hiddenFlag;
  enInfo();
};
const enInfo = () => {
  if (data.hiddenFlag) {
    form.value.realProperty = hideRealProperty(form.value.realProperty);
  } else {
    form.value.realProperty = oldForm.value.realProperty;
  }
};
const hideRealProperty = (val: any) => {
  if (!val) {
    return;
  }
  let output = [];
  for (let i = 0; i < val.length; i++) {
    if (val[i].match(/[0-9a-z]/)) {
      output.push('*');
    } else {
      output.push(val[i]);
    }
  }
  return output.join('');
};
// ------------------钩子函数----------------------------
// 初始化
onMounted(() => {
  enInfo();
});
watch(
  () => props.houseInfo,
  () => {
    form.value = Object.assign({}, props.houseInfo);
    oldForm.value = Object.assign({}, props.houseInfo);
    enInfo();
  },
  { deep: true }
);
</script>
<style lang="scss" scoped></style>
